package com.example.AI;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.example.AI.param.CreateParam;

import java.io.File;
import java.util.HashMap;

public class FineTunes {
    private final String BearerToken = "Bearer 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";
    private static final String PROXY_BASE_URL = "http://43.156.74.238/";
    private static final String CHAT = "v1/chat/completions";
    private static final String IMAGE = "v1/images/generations";
    private static final String MODEL = "gpt-3.5-turbo-0301";
    private static final String UPLOAD = "v1/files";
    private static final String CREATE = "v1/fine-tunes";
    public void uploadFile() {
        File file = new File("C:\\Users\\admin\\Desktop\\promt.jsonl");
        HttpRequest post = HttpUtil.createPost(PROXY_BASE_URL + UPLOAD);
        post.header("Authorization", BearerToken);
        post.contentType("application/json");
        post.form("file", file);
        post.form("purpose", "fine-tune");
        HttpResponse response = post.execute();
        System.out.println(response.body());
    }

    public void deletdFile() {
        HttpRequest delete = HttpRequest.delete(PROXY_BASE_URL + UPLOAD + "/file-ydffhKly4QaWJ2zelmFmNitA");
        delete.header("Authorization", BearerToken);
        HttpResponse response = delete.execute();
        System.out.println(response.body());
    }

    public void create() {
        CreateParam param = new CreateParam();
        param.setTraining_file("file-nSdwsMHZ1LptALWCkXygjQaj");
        param.setModel("curie");
        param.setSuffix("gaoshan-curie-001");
        HttpRequest post = HttpUtil.createPost(PROXY_BASE_URL + CREATE);
        post.header("Authorization", BearerToken);
        post.body(JSONUtil.toJsonPrettyStr(param));
        HttpResponse response = post.execute();
        System.out.println(response.body());
    }

    public void list() {
        HttpRequest get = HttpUtil.createGet(PROXY_BASE_URL + CREATE);
        get.header("Authorization", BearerToken);
        HttpResponse response = get.execute();
        System.out.println(response.body());
    }

    public static void main(String[] args) {
//        FineTunes fineTune = new FineTunes();
//        //fineTune.uploadFile();
//        //fineTune.deletdFile();
//        //fineTune.create();
//        fineTune.list();
        HashMap<String, String> map = new HashMap<>();
        map.put("aaa", "bbb");
        System.out.println(map.get("ccc"));
    }

}
